import { CaretDownOutlined, CaretRightOutlined } from "@ant-design/icons";

export const getTableExpandIcon = (props: any, dataSource?: any[], childrenFieldName: string = "children") => {
  // 每一项都没有子级时
  if (dataSource?.length && !dataSource?.some((item: any) => item[childrenFieldName]?.length > 0)) return <></>;
  const { expanded, onExpand, record } = props;
  if (!record[childrenFieldName]?.length) return <span style={{ marginRight: 20 }}></span>;
  return expanded ? (
    <CaretDownOutlined style={{ marginRight: 4 }} onClick={(e) => onExpand(record, e)} />
  ) : (
    <CaretRightOutlined style={{ marginRight: 4 }} onClick={(e) => onExpand(record, e)} />
  );
};

